<?php

class_exists('MPVehicles') || require('class.MPVehicles.php');

class MPTrip
{
	private $m_origin;
	private $m_destination;
	private $m_seats_used;
	
	public function __construct($origin,$destination,$seated)
	{
		$this->m_origin = $origin;
		$this->m_destination = $destination;
		$this->m_seats_used = $seated;
	}
	
	public function set_origin($origin)
	{
		$this->m_origin = $origin;
	}
	
	public function set_destination($destination)
	{
		$this->m_destination = $destination;
	}
	
	public function get_origin()
	{
		return $this->m_origin;
	}
	
	public function get_destination()
	{
		return $this->m_destination;
	}
	
	public function get_seats_used()
	{
		return $this->m_seats_used;
	}
	
	public function add_passenger($wheelchair,$maxCapacity)
	{
		$seated = true;
		$seatsUsed = $this->m_seats_used;
		
		if( $wheelchair )
		{
			// add the passenger as a wheelchair user
			
		}
		else $seating += 1;
		
		if( $seatsUsed > $maxCapacity ) $seated = false;
		else $this->m_seats_used = $seatsUsed;
		
		return $seated;
	}
}

class MPTrips
{
	private $m_trips;
	private $m_vehicle;
	
	public function __construct($vehicle)
	{
		// Code for populating the array with data from database would go here
		// $vehicle is the vehicle's registration number
		$this->m_trips = array();
		$this->m_vehicle = $vehicle;
	}
	
	public function load_from_db($db)
	{
		$trips = $db->getTrips($this->m_vehicle);
		
		foreach( $trips as $t )
		{
			$tripTemp = new MPTrip($t['origin'],$t['destination'],$t['seats_used']);
			$this->m_trips[] = $tripTemp;
		}
	}
	
	public function get_vehicle()
	{
		return $this->m_vehicle;
	}
	
	public function get_trips()
	{
		return $this->m_trips;
	}
	
	public function add($trip)
	{
		$this->m_trips[] = $trip;
	}
	
	public function remove($id)
	{
		for( $i = $id; $i < $this->m_trips.length - 1; ++$i )
			$this->m_trips[$i] = $this->m_trips[$i+1];
		array_pop( $this->m_trips[$i] );
	}
	
	public function clear()
	{
		unset($this->m_trips);
		$this->m_trips = array();
	}
}

?>